Skip to content

Write named tuples, complex numbers, irrationals, and non-string keys as YAML values - #279

Merged
quinnj-bot[bot] merged 3 commits into
masterfrom
claude/write-namedtuples-keys
Nov 18, 2026
Merged

quinnj-bot[bot] merged 3 commits into
masterfrom
claude/write-namedtuples-keys

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Why

YAML.write wrote named tuples, complex numbers, irrationals such as π, and dictionary keys that aren't text as Julia source text. They loaded back as strings: (a = 1,) became "(a = 1,)", and the key Inf became "Inf". A tuple key holding ": " gave YAML that didn't load at all.

What changed

  • Named tuples are written as mappings.
  • Complex numbers are written as a mapping with keys re and im, the shape JSON.jl writes. YAML has no complex type, and the writer can't emit tags.
  • Irrationals are written as the nearest float, as rationals already are.
  • A key that isn't text is written the way the same value would be, so Inf becomes .inf and 1//2 becomes 0.5. A nonempty collection key (tuple, vector, set, dict, named tuple, complex) is written as an explicit ? key, so Dict((1, 2) => 3) loads back as Dict([1, 2] => 3).

For example, YAML.yaml((name = "a", pos = 1 + 2im, k = Dict((1, 2) => pi))) now gives:

name: "a"
pos:
  re: 1
  im: 2
k:
  ?
    - 1
    - 2
  : 3.141592653589793

Scope

  • Integer, Bool, string, Symbol, Char, nothing, and missing keys are written as before. Round 1's corpus of 20,000 values of the other supported types writes byte-identical output.
  • The README sentence about written types now covers named tuples, irrationals, complex numbers, and keys.

Tradeoffs

  • A complex number could be written as the quoted string "1 + 2im". That keeps Julia's syntax, but no YAML reader loads it as a number. The mapping keeps both parts numeric in every reader.

Blast Radius

Verification

  • The new testset has 53 failures and 5 errors in 70 on master, and passes 70 of 70 here.
  • YAML.jl, Psych, yq, eemeli yaml, and js-yaml load all 21 written named-tuple, complex, and irrational values (top level, dict value, list item) as the expected values. Psych reads all 12 written key forms as typed keys (Infinity, [1, 2], {"a"=>1}, and so on).
  • Full Pkg.test() passes on Julia 1.12.6 and on Julia 1.0.5 (Docker).

🤖 Generated with Claude Code

quinnj and others added 2 commits November 18, 2026 04:44
…keys load back

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… as YAML values

Named tuples, complex numbers, and irrationals fell through to string(),
and keys other than text used string(k). They loaded back as Julia text,
and a tuple key holding ': ' gave YAML that didn't load. Named tuples
are now written as mappings, complex numbers as a re/im mapping (JSON.jl's
form), irrationals as the nearest float, scalar keys as their values
would be, and collection keys as explicit '?' keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.64%. Comparing base (dc025fb) to head (703aac1).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #279      +/-   ##
==========================================
+ Coverage   91.48%   91.64%   +0.15%     
==========================================
  Files          15       15              
  Lines        1715     1735      +20     
==========================================
+ Hits         1569     1590      +21     
+ Misses        146      145       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

A Pair key was written as "1: 2: 3", which doesn't load. Treating Pair
as a mapping writes it with an explicit '?' key when it is a key and as
a nested mapping when it is a value, and both load back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quinnj-bot
quinnj-bot Bot merged commit cf66576 into master Nov 18, 2026
22 checks passed
@quinnj-bot quinnj-bot Bot mentioned this pull request Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant